﻿namespace WPForms.Phone.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using WPForms.Common.Model;

    /// <summary>
    /// This specific dictonary stores the view models that should handle the display of specific model
    /// classes.
    /// </summary>
    public class ViewModelMap
    {
        /// <summary>
        /// The inner dictionary
        /// </summary>
        private Dictionary<Type, Type> typeDictionary = new Dictionary<Type, Type>();

        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelMap" /> class.
        /// </summary>
        public ViewModelMap()
        {
        }

        /// <summary>
        /// Gets the view model <see cref="Type" /> for the specified model type.
        /// </summary>
        /// <param name="modelType">Type of the model.</param>
        /// <returns>The type of the view model</returns>
        public Type this[Type modelType]
        {
            get
            {
                Type ret = null;
                this.typeDictionary.TryGetValue(modelType, out ret);
                return ret;
            }
        }

        /// <summary>
        /// Registers a view model type for the given model type.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <typeparam name="TViewModel">The type of the view model</typeparam>
        public void Register<TModel, TViewModel>()
            where TModel : FormElement
            where TViewModel : ElementViewModelBase<TModel>
        {
            this.typeDictionary[typeof(TModel)] = typeof(TViewModel);
        }
    }
}
